<template>
  <div>
    <a-modal title="置顶" :visible="visible" @ok="handleOk" :confirmLoading="confirmLoading" @cancel="handleCancel">
      <a-row>
        <a-input-number :min="1" placeholder="置顶排序" v-model="record.sort" @change="onChange" />

        <a-select
          mode="tags"
          style="width: 60%;margin-left: 20px;"
          placeholder="置顶标签(可不填)"
          v-model="editTopTag"
          :allowClear="true">
          <a-select-option v-for="(tag,index) in record.topTags" :key="index" :value="tag">{{ tag }}</a-select-option>
        </a-select>

      </a-row>
      <a-divider dashed />
      <a-row>
        <a-switch v-model="record.istop" checkedChildren="设为置顶" unCheckedChildren="取消置顶" />
        <a-divider type="vertical" />
        <a-switch v-model="record.isrecomd" checkedChildren="设为推荐" unCheckedChildren="取消推荐" />
        <a-divider type="vertical" />
        <a-switch v-model="record.isheadline" checkedChildren="设为头条" unCheckedChildren="取消头条" />
      </a-row>

    </a-modal>
  </div>
</template>
<script>
  import {
    topIt
  } from '@/api/site/content'
  export default {
    data () {
      return {
        visible: false,
        confirmLoading: false,
        editTopTag: [],
        record: {
          istop: false,
          id: null,
          isrecomd: false,
          isheadline: false,
          sort: 1,
          topTags: []
        }
      }
    },
    methods: {
      top (record) {
        this.visible = true
        this.id = record.id
        this.record = {
          istop: record.istop,
          id: record.id,
          isrecomd: record.isrecomd,
          isheadline: record.isheadline,
          sort: record.sort
        }
        if (record.topTag) {
          this.editTopTag = record.topTag.split(',')
        } else {
          this.editTopTag = []
        }
      },
      handleOk (e) {
        this.record.topTags = this.editTopTag
        topIt(this.record).then(response => {
          if (response.code === 0) {
            this.$emit('ok')
            this.handleCancel()
            this.$message.info(response.msg)
          } else {
            this.$message.error(response.msg)
          }
        })
      },
      handleCancel (e) {
        this.visible = false
      },
      onChange (e) {

      }
    }
  }
</script>
